package com.mind.ridge.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mind.ridge.dto.backend.SetmealDishDto;
import com.mind.ridge.pojo.backend.Setmeal;
import com.mind.ridge.service.backend.SetmealService;
import com.mind.ridge.utils.R;
import lombok.extern.java.Log;
import lombok.extern.slf4j.Slf4j;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Mind
 */
@RestController
@RequestMapping("/setmeal")
@Slf4j
public class SetmealController {

    @Resource
    private SetmealService setmealService;

    @GetMapping("/page")
    public R<IPage> page(@RequestParam("page") int currentPage,
                         @RequestParam("pageSize") int pageSize,
                         @Nullable String name){
        log.info("当前页数：{}，页面大小：{}，套餐名称{}",currentPage,pageSize,name);
        return setmealService.pageSet(currentPage,pageSize,name);
    }

    @PostMapping
    public R<String> add(@RequestBody SetmealDishDto dto){
        return setmealService.add(dto);
    }

    @PostMapping("/status/{status}")
    public R<String> alterStatus(@RequestParam("ids") Long[] ids, @PathVariable int status){

        log.info("id:{},status:{}",ids,status);
        return setmealService.alterStatus(ids,status);

    }

    @DeleteMapping
    public R<String> delete(Long[] ids){
        log.info("ids:{}",ids);
        return setmealService.delete(ids);
    }

    @GetMapping("/{id}")
    public R<SetmealDishDto> echoInfo(@PathVariable long id){
        log.info(id+"");
        return setmealService.echoInfo(id);
    }

    @PutMapping
    public R<String> updateModify(@RequestBody SetmealDishDto dto){
        log.info(dto.toString());
        return setmealService.updateModify(dto);
    }

    @GetMapping("/list")
    public R<List<SetmealDishDto>> list(@RequestParam("categoryId")Long categoryId, @Nullable Integer status){
        return setmealService.setmealList(categoryId, status);
    }
}
